"""
封装接口对象层
"""
import requests

from common.assert_tools import common_assert
from common.get_header_tools import get_header


class IhrmEmpApi(object):
    # 添加员工
    def add_emp(self, req_header, req_body):
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user",
                             headers=req_header, json=req_body)
        return resp

    # 查询员工
    def query_emp(self, emp_id, req_header):
        resp = requests.get(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                            headers=req_header)
        return resp

    # 修改员工
    def modify_emp(self, emp_id, req_header, req_body):
        resp = requests.put(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                            headers=req_header, json=req_body)
        return resp

    # 删除员工
    def delete_emp(self, emp_id, req_header):
        resp = requests.delete(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                               headers=req_header)
        return resp


if __name__ == '__main__':
    # 创建实例
    ihrm = IhrmEmpApi()
    # 创建请求头-调用我们自己封装的工具方法
    req_header = get_header()
    # 准备添加员工请求体
    req_body = {
        "username": "user87655431",
        "mobile": "13947884787",
        "workNumber": "9527890ab"
    }
    # 调用员工方法
    resp = ihrm.add_emp(req_header, req_body)
    # 打印添加运功结果
    print("添加员工成功", resp.json())
    # 准备员工id
    emp_id="1609848361249157120"
    #查询测试员工
    resp=ihrm.query_emp(emp_id,req_header)
    print("查询员工",resp.json())
    #断言
    common_assert(resp,200,True,10000,"操作成功")
